﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    PlanReport
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    
    <style type="text/css">
.hide
{
    display:none;
}
</style>
    <div id="tabs">
        <ul>
            <li><a href="#tabs-2">Planning Data</a></li>
        </ul>
        <div id="tabs-1" style="min-height: 500px; margin-left: 0px;">
        <div id="Header" style="font-weight:bold; margin-top:10px;">DATE : <%=  ViewBag.dt  %></div>
            <table id="cart" style="display: none">
            </table>
        </div>
    </div>
    <div id="dialog-add" title="Search">
        <table>
            <tr>
                <td>
                    Date
                </td>
                <td>
                <input id="txtdate" type="text" value="<%=  ViewBag.dt  %>"  />
                </td>
            </tr>
        </table>
    </div>

</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="FeaturedContent" runat="server">
</asp:Content>

<asp:Content ID="Content4" ContentPlaceHolderID="ScriptsSection" runat="server">
    <script type="text/jscript">
        $(function () {
            $("#tabs").tabs();
            $('#txtdate').dateEntry({ useMouseWheel: false, dateFormat: 'dmy/' })
            var newURL = '<%= Url.Action("CartExport") %>' + '?dSearch=' + $("#txtdate").val();
            var nonExp = false;
            var Exp = false;
            $("#dialog-add").dialog({
                width: 350,
                height: 180,
                autoOpen: false,
                open: function (event, ui) {
                    setTimeout(function () { $("#txtdate").focus(); }, 1000);
                },
                show: "blind",
                buttons: {
                    "ค้นหา": function () {
                        if ($('#txtdate').val() == "") {
                            $().toastmessage('showErrorToast', 'Pleas Input Date.');
                            return;
                        }
                        newURL = '<%= Url.Action("CartExport") %>' + '?dSearch=' + $("#txtdate").val();
                        $("#dialog-add").dialog("close");
                        $("#Header").html("DATE : " + $("#txtdate").val());
                        $("#cart").flexgridReload(newURL);
                    },
                    "ยกเลิก": function () {
                        $("#dialog-add").dialog("close");
                    }
                }
            });

            function open_dialog() {
                if ($('#txtdate').val() == "") {
                    $().toastmessage('showErrorToast', 'Pleas Input Date.');
                    return;
                }
                $("#dialog-add").dialog("open");
            }
            function nonexport() {
                if ($('#txtdate').val() == "") {
                    $().toastmessage('showErrorToast', 'Pleas Input Date.');
                    return;
                }
                nonExp = true;
                Exp = false;
                newURL = '<%= Url.Action("CartExport") %>' + '?dSearch=' + $("#txtdate").val() + '&nonExport=true';
                $("#Header").html("NonExported View " + "DATE : " + $("#txtdate").val());
                $("#cart").flexgridReload(newURL);
            }
            function exportdata() {
                if ($('#txtdate').val() == "") {
                    $().toastmessage('showErrorToast', 'Pleas Input Date.');
                    return;
                }
                nonExp = false;
                Exp = true;
                newURL = '<%= Url.Action("CartExport") %>' + '?dSearch=' + $("#txtdate").val() + '&Export=true';
                $("#Header").html("Exported View " + "DATE : " + $("#txtdate").val());
                $("#cart").flexgridReload(newURL);
            }
            function dowloaddata() {
                if ($(".download").hasClass("hide")) {
                    $().toastmessage('showWarningToast', 'No data Export');
                    return;
                }
                setTimeout(function () {
                    // Do something after 2 seconds
                    $("#cart").flexgridReload(newURL);
                }, 3000);

                $.download('<%=Url.Action("Export_data") %>', "dSearch=" + $("#txtdate").val() + "&nonExport=" + nonExp + "&Export=" + Exp)

            }

            $("#cart").flexigrid({
                url: newURL,
                dataType: 'json',
                colModel: [
				{ display: 'Date', name: '_Count_date', width: 100, sortable: true, align: 'center' },
				{ display: 'Size', name: '_Size', width: 120, sortable: true, align: 'left' },
				{ display: 'F/M', name: '_Forming', width: 30, sortable: true, align: 'center' },
				{ display: 'P1', name: '_P1', width: 75, sortable: true, align: 'center' },
				{ display: 'P2', name: '_P2', width: 75, sortable: true, align: 'center' },
                { display: 'P3', name: '_P3', width: 75, sortable: true, align: 'center' },
                { display: 'P4', name: '_P4', width: 75, sortable: true, align: 'center' },
                { display: 'Top', name: '_Top', width: 40, sortable: true, align: 'center' },
                { display: 'Tape', name: '_Tape', width: 40, sortable: true, align: 'center' },
                { display: 'Ng', name: '_Ng', width: 40, sortable: true, align: 'center' },
                { display: 'Expired', name: '_Exp', width: 100, sortable: true, align: 'center' },
                { display: 'Cart Type', name: '_Type', width: 60, sortable: true, align: 'center' }
                ],
                buttons: [
                { name: '   Search', bclass: 'newSearch', onpress: open_dialog },
                { name: '   Export To Excel', bclass: 'download', onpress: dowloaddata },
                  { separator: true },
                { name: '   NonExported View', bclass: 'nonexport', onpress: nonexport },
                { name: '   Exported View', bclass: 'export', onpress: exportdata }
                ],
                sortname: '_Count_date',
                sortorder: 'asc',
                usepager: true,
                rp: 15,
                width: 950,
                height: 400, singleSelect: true,
                preProcess: function (jsondata) {
                    if (jsondata.total == 0) {
                        $(".download").addClass("hide");
                    } else $(".download").removeClass("hide");
                    return jsondata;
                }
            });


        });
    </script>
</asp:Content>
